package com.qfedu.mesadmin.md.item.controller;

import com.qfedu.mes.common.CommonResult;
import com.qfedu.mes.common.PageVO;
import com.qfedu.mesadmin.md.item.params.AddItemParam;
import com.qfedu.mesadmin.md.item.params.ItemPageParam;
import com.qfedu.mesadmin.md.item.service.ItemService;
import com.qfedu.mesadmin.md.item.vo.ItemVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/md/item")
public class MdItemController {

    @Resource
    private ItemService itemService;

    @GetMapping("/page")
    public CommonResult pageItem(ItemPageParam pageParam) {
        PageVO<ItemVO> pageVO = itemService.pageItem(pageParam);
        return CommonResult.success(pageVO);
    }

    /**
     * 自动生成itemcode
     *
     * @return
     */
    @GetMapping("/code/auto")
    public CommonResult createItemCode() {
        String itemCode = itemService.createItemCode();
        return CommonResult.success(itemCode);
    }

    /**
     * 添加物料
     *
     * @param param
     * @return
     */
    @PostMapping("/add")
    public CommonResult addItem(@RequestBody AddItemParam param) {
        itemService.addItem(param);
        return CommonResult.success();
    }
    
}
